﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;

using System.Text;
using System.Windows.Forms;
using System.Net;
using System.Net.Sockets;
using System.Threading;
using System.IO;

namespace ServerApp
{
    public partial class Form1 : Form
    {
       static UDPServices udpServices = new UDPServices();
       static NetworkStream clientStream;
       static bool write = false;
       
        public Form1()
        {
            InitializeComponent();

            
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            try
            {
                udpServices.server_Load();
               
            }
            catch (Exception ex)
            {
               // MessageBox.Show(ex.ToString());
            }
         
        }
        public void returnIP()
        {
            String abc = udpServices.returnIP();
            MessageBox.Show("IP is : " + abc);
        }

        private void button1_Click(object sender, EventArgs e)
        {

            //Thread listenThread = new Thread(new ThreadStart(run));
           // listenThread.Start();
            //listenThread.IsBackground = true;
           // run();
            //TCPservices abc = new TCPservices();
           // abc.testConnectTCP();
        }
        public void run()
        {
            TcpClient client = new TcpClient();
            IPEndPoint serverEndpoint = new IPEndPoint(IPAddress.Parse("192.168.1.146"), 8080);
            client.Connect(serverEndpoint);
            clientStream = client.GetStream();
            ASCIIEncoding encoder = new ASCIIEncoding();
            byte[] buffer;
            while (true)
            {
                buffer = encoder.GetBytes("GO");
                clientStream.Write(buffer, 0, buffer.Length);
                clientStream.Flush();
            }
        }
      
        
    }
}
